// 云函数入口文件
const cloud = require('wx-server-sdk')
const env = 'bbq-6gz7knah1c296b0f'
cloud.init(env)

const db = cloud.database({env})

// 云函数入口函数
exports.main = async (event, context) => {
    if(event.code == 0){
      await db.collection('articles').doc(event.articleId).update({data:{praises:db.command.pull(event.praiseId)}})
            db.collection('users').where({userId:event.praiseId}).update({data:{praises:db.command.pull(event.articleId)}})
    }else{
      await db.collection('articles').doc(event.articleId).update({data:{praises:db.command.push(event.praiseId)}})
            db.collection('users').where({userId:event.praiseId}).update({data:{praises:db.command.push(event.articleId)}})
    }

    return await db.collection('articles').doc(event.articleId).get()

}

